a = 'hello'
print(a, type(a))
# 编码
a1 = a.encode()
print("编码后：", a1)
print(type(a1))
# 解码
a2 = a1.decode()
print(a2, type(a2))

st = "这里是哈哈哈"
st1 = st.encode("utf-8")
print(st1, type(st1))
st2 = st1.decode("utf-8")
print(st2, type(st2))
# 字符串拼接
st1 = "Hello"
st2 = "Word"
print(st1 + st2)
print(st1, st2, sep="-")
# * 重复输出
print("好好学习，天天向上！\n" * 5)
print('&\t' * 10)
# 成员运算符 是否包含 in 、not in
name = "hello python!"
print('p' in name)
print('h' not in name)
print('py' in name)
# 下标索引
print(name[2])
for e in name:
    print(e)
# 截取字符串
st = 'abcdefghijk'
print(st[0:4])
print(st[3:6])
# [开始位置:结束位置:步长] 步长不写默认为 1，负数表示从右往左
print(st[-1:])
print(st[:-1])
print(st[-1::-1])
print(st[-1:-5:-1])
print(st[0:7:2])
# 字符串查找
name = "zhangsan"
# find() 返回下标 -1 表示没有找到
print(name.find('sa'))
# 从 0 位置开始查找
print(name.find('ha', 0))
# 从 0 到 3 范围查找
print(name.find('ha', 0, 3))
# index() 没找到会报错
print(name.index('g'))
print(name.index('n', 2, 5))
# count() 统计出现次数
name = 'wangwu,heiheiya'
print(name.count('ya'))
print(name.count('hei', 3, 9))
# 转为小写
print(name.lower())
# 转为大写
print(name.upper())
# startswith() 判断以wa开头
print(name.startswith('wa'))
print(name.startswith('wa', 0))
print(name.startswith('wa', 0, 5))
# endswith() 判断以wu结尾
print(name.endswith('wu', 0))
print(name.endswith('wu', 0, 6))
# isupper() 是否全部为大写
print(name.isupper())
print(name.upper().isupper())
# replace() 替换元素
print(name.replace('wu', 'liu'))
# split() 切割字符串
print(name.split(','))
# capitalize() 第一个字符大写
print(name.capitalize())
